package com.aispeech.asr.apis.ssc.data.repository;

import org.springframework.data.mongodb.repository.Query;
import org.springframework.data.mongodb.repository.ReactiveMongoRepository;
import org.springframework.stereotype.Repository;

import com.aispeech.asr.apis.ssc.data.domain.TaskDoc;

import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

@Repository
public interface TaskRepository extends ReactiveMongoRepository<TaskDoc, String> {
    Mono<TaskDoc> findByIdAndProductId(String id, String productId);
    Mono<TaskDoc> findById(String id);
    Flux<TaskDoc> findAllByParentId(String parentId);

    @Query(
            fields="{ 'hostname':1, 'metrics':1, 'progress':1, 'request.duration':1, 'request.audioLength':1, 'request.audioType':1, 'request.appId':1 }",
            sort = "{ progress:-1, update_t:-1 }")
    Flux<TaskDoc> findAllByProgressLessThan(int progress);
}
